const baseURL = "https://tea.qingnian8.com"

export function request(params) {
    
    let data = params.data
    let header = {
        'content-type': 'application/json'
    }
    let method = params.method || "GET"
    let url = baseURL + params.url

    return new Promise((resolve, reject) => {
        wx.request({url, header, method, data,
          success: (response) => {
              if (response.data.errCode != 0) {
                reject(response.data)
                wx.showToast({
                  title: response.data.errMsg,
                  mask: "true",
                  icon: "error"
                })
                return
              }
              resolve(response.data)
          },
          fail: (error) => {
              reject(error)
          }
        })
    })
}